- main_toolbar do |t|
  = t.edit resource

- main_period_selector(:year)

= main_informations attachment: true do
  = render 'picture'
  = infos do
    = product_info(:work_number, important: true)
    .med-info.important
      - icon = resource.category.pictogram
      %span.title= Equipment.human_attribute_name(:variant)
      %span.value
        %i.picto{class: "picto-#{icon}"}
        = link_to(resource.variant_name, controller: :product_nature_variants, action: :show, id: resource.variant_id)
    - if resource.born_at and resource.age >= 1.day
      = product_info(:age) do |age|
        %i.picto{class: "picto-clock-o"}
        = human_age(resource.born_at, display: 2)
    .med-info.important
      %span.title= Equipment.human_attribute_name(:state)
      %span.value= lights(resource.status)
    - if resource.remaining_working_lifespan || resource.remaining_lifespan
      .med-info.important
        %span.title= :wear.tl
        %span.value= lights(resource.wear_status)
    .med-info
      %span.title= Equipment.human_attribute_name(:working_duration)
      %span.value
        %i.picto{class: "picto-timelapse"}
        = resource.current_work_life.in_hour.round(2).l precision: 1
    - if resource.remaining_working_lifespan
      .med-info
        %span.title= Equipment.human_attribute_name(:remaining_working_lifespan)
        %span.value
          %i.picto{class: "picto-timelapse"}
          = resource.remaining_working_lifespan.in_hour.round(2).l precision: 1
    - if resource.remaining_lifespan
      .med-info
        %span.title= Equipment.human_attribute_name(:remaining_lifespan)
        %span.value
          %i.picto{class: "picto-timelapse"}
          = resource.remaining_lifespan.in_hour.round(2).l precision: 1
    - unless resource.description.blank?
      .med-info
        %span.title= Equipment.human_attribute_name(:description)
        %span.value= resource.description
  = labels_info(resource.labels)

= cobbles do |c|

  - if resource.intervention_product_parameters.any?
    - c.cobble(:intervention_product_parameters, title: :x_interventions.tl(count: resource.interventions.count)) do
      = cobble_list(:intervention_product_parameters)

  - if resource.issues.any?
    - c.cobble(:issues, title: :x_issues.tl(count: resource.issues.count)) do
      = cobble_toolbar do |t|
        = cobble_list(:issues)

  - if resource.fixed_assets.any?
    - c.cobble(:fixed_assets, title: :x_fixed_assets.tl(count: resource.fixed_assets.count)) do
      = cobble_toolbar do |t|
        = cobble_list(:fixed_assets)

  - time_spent_by_activity(resource, cobbler: c)

  - c.cobble(:places) do
    = cobble_toolbar do |t|
      .toolbar
        = tool_to :new.ta, {action: :new, controller: :product_localizations, product_id: resource.id }, tool: :new
      = cobble_list(:places)

  - if resource.components.any?
    - c.cobble(:components) do
      .component-tree
        .component
          .component-head
            .component-col.component-heading= ProductNatureVariantComponent.human_attribute_name(:name)
            .component-col.component-type= ProductNatureVariantComponent.human_attribute_name(:product_nature_variant)
            .component-col.component-status= ProductNatureVariantComponent.human_attribute_name(:status)
            .component-col.component-life= ProductNatureVariantComponent.human_attribute_name(:working_duration)
            .component-col.component-wear= ProductNatureVariantComponent.human_attribute_name(:replaced_at)
            .component-col.component-count= ProductNatureVariantComponent.human_attribute_name(:replacements)

        = render 'components', equipment: resource, components: resource.variant.root_components, depth: 0

